package org.grow.cooldown.CookModule;

import org.grow.cooldown.CookModule.entity.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/cook/")
public class CookCtrl {

    @Autowired
    MongoTemplate mongoTemplate;
    @PostMapping("/mono/")
    public Dish postDish(@RequestBody Dish dish){
        dish.setDisCreateT(LocalDateTime.now());
        if (dish.getMajorM()==null){
            throw new Dish.CookException(2001,"miss major material");
        }
        Dish save = mongoTemplate.save(dish);
        return save;
    }



}
